package com.edu.controller;

import com.edu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *  后端向前端返回JSON字符串的案例
 */
@Controller
@RequestMapping("/json")
public class JsonController1 {

    @RequestMapping("/getAUser")
    @ResponseBody //表示下面的方法 只负责 返回数据。返回json数据
    public Object getUser(){
        System.out.println("执行了getUser");
        User user = new User(1,"zhangsan","123456",18,new Date(),"562669473@qq.com");
        return user;
    }

    @RequestMapping("/getUsers")
    @ResponseBody
    public Object getUsers(){
        System.out.println("执行了getUsers");
        User user1 = new User(1,"zhangsan","123456",18,new Date(),"5622669473@qq.com");
        User user2 = new User(2,"lisi","1234526",18,new Date(),"562669asd473@qq.com");
        User user3 = new User(3,"shufen","1223456",18,new Date(),"56233669473@qq.com");

        List<User> list = new ArrayList();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        return list;
    }
}
